package day6;

import day4.BankAcc;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class ColTest2 {
    public static void main(String[] args) {
        List<BankAcc> list = new ArrayList<>();
        list.add(new BankAcc("hf--5","小蔡","3111","hefei",50333.0F));

        list.add(new BankAcc("hf--1","老吴","123","shanghai",1000000.0F));
        list.add(new BankAcc("hf--2","小刘","1243","shanghai",100030.0F));
        list.add(new BankAcc("hf--3","小李","1523","nanjing",60000.0F));
        list.add(new BankAcc("hf--4","老张","623","shanghai",1000.0F));

        BankAcc m0 =(BankAcc) Collections.max(list);
        System.out.println("默认规则："+m0);
        BankAcc m1 = Collections.max(list, new MyComp());
        System.out.println("规则2："+m1);
        BankAcc m3 = Collections.max(list, new MyComp2());
        System.out.println("规则3,按照名字来比较："+m3);

        Comparator<BankAcc> bijiaoqi=(x,y)->{
            return (int) (x.getMoney()-y.getMoney());
        };

        BankAcc m4 = Collections.max(list, (x,y)->{
            return (int) (x.getMoney()-y.getMoney());
        });
        System.out.println("规则4,按照钱多少来比较："+m4);
    }
}
class MyComp implements Comparator<BankAcc>{

    @Override
    public int compare(BankAcc o1, BankAcc o2) {
        if(o1.getNo()==null){
            if(o2.getNo()==null)
                return 0;
            return -10000;
        }
        return o1.getNo().compareTo(o2.getNo());
    }
}
class MyComp2 implements Comparator<BankAcc>{

    @Override
    public int compare(BankAcc o1, BankAcc o2) {
        if(o1.getName()==null){
            if(o2.getName()==null)
                return 0;
            return -10000;
        }
        return o1.getName().compareTo(o2.getName());
    }
}